//
//  ProcessView.swift
//  MikerShop
//
//  Created by eme on 2017/2/23.
//  Copyright © 2017年 eme. All rights reserved.
//

import UIKit
import SnapKit
import RickonCore
/// 自定义的进度view
class ProcessView: UIView {
    
    var show_percent_Lb = UILabel()
    var percent:CGFloat = 0.0{
        didSet{
            self.show_percent_Lb.text = "\(Int(self.percent * 100))%"
            self.setNeedsDisplay()
        }
    }
    override func awakeFromNib() {
        self.backgroundColor = UIColor(hex: "fba3a0")
        self.changeBorderColor(UIColor.clear,cornerRadius:self.v_hegith/2)
        setupSubviews()
    }
    
    
    func setupSubviews() {
        show_percent_Lb.textAlignment = .center
        show_percent_Lb.textColor = UIColor.white
        show_percent_Lb.font = UIFont(name: Theme.fontName, size: 10)
        show_percent_Lb.backgroundColor = UIColor.clear
        
        self.addSubview(show_percent_Lb)
        show_percent_Lb.snp.makeConstraints{ make in
            make.center.equalToSuperview()
        }
    
    }
    
    override func draw(_ rect: CGRect) {
        if let context = UIGraphicsGetCurrentContext(){
            let start:CGFloat = 0.0
            context.move(to: CGPoint(x: start, y: 0))
            context.addLine(to: CGPoint(x: self.frame.width*percent, y: 0))
            context.addLine(to: CGPoint(x: self.frame.width*percent, y: self.frame.height))
            context.addLine(to: CGPoint(x: 0, y: self.frame.height))
            context.closePath()
            UIColor(hex: "fd6863").setFill()
            UIColor(hex: "fd6863").setStroke()
            context.drawPath(using: CGPathDrawingMode.fillStroke)
        }
    }
    
    
}

